package com.xqy.config;


import com.alibaba.druid.pool.DruidDataSource;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;

import com.xqy.modle.User;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;


/**
 * description: JfinalActiveRecordConfig
 * date: 2020/9/22 13:00
 * author: ASUS
 * version: 1.0
 */

@Configuration
public class JfinalActiveRecordConfig {
    /**
     * 主数据源名称
     */
    private static final String MAIN_DATA_SOURCE_CONFIG = "main";
    @Bean
    @ConfigurationProperties("spring.datasource.main")
    public DruidDataSource masterDataSource(){
        return new DruidDataSource();
    }

    /**
     * 主数据源
     * @return
     */
    @Bean
    public ActiveRecordPlugin initMainActiveRecord() {
        ActiveRecordPlugin arp = new ActiveRecordPlugin(MAIN_DATA_SOURCE_CONFIG,masterDataSource());
        arp.addMapping("user", User.class);
        arp.setShowSql(true);//显示sql语句
        arp.start();
        return arp;
    }










}
